function formatDate(nowTimer) {
	let formats = {
		year: '几 年前',
		month: '几 月前',
		day: '几 天前',
		hour: '几 小时前',
		minute: '几 分钟前',
		second: '几 秒前'
	};
	//获取当前时间戳
	let now = Date.now();
	let seconds = Math.floor((now - nowTimer * 1000) / 1000);
	let minutes = Math.floor(seconds / 60);
	let hours = Math.floor(minutes / 60);
	let days = Math.floor(hours / 24);
	let months = Math.floor(days / 30);
	let years = Math.floor(months / 12);
	let oldType = '';
	let oldValue = 0;
	if (years > 0) {
		//几年前
		oldType = 'year';
		oldValue = years;
	} else {
		if (months > 0) {
			//几个月前
			oldType = 'month';
			oldValue = months;
		} else {
			if (days > 0) {
				//几天前
				oldType = 'day';
				oldValue = days;
			} else {
				if (hours > 0) {
					//几小时前
					oldType = 'hour';
					oldValue = hours;
				} else {
					//这里  您可以处理一个  刚刚  比如时间小于30分钟
					if (minutes > 0) {
						//几分钟前
						oldType = 'minute';
						oldValue = minutes;
					} else {
						//几秒前
						oldType = 'second';
						oldValue = seconds === 0 ? (seconds = 1) : seconds;
					}
				}
			}
		}
	}
	return formats[oldType].replace('几', oldValue);
}

function formatDistance(nowDis) {
	return (nowDis / 1000).toFixed(2)
}

function formatDates(time) { //时间戳转日期
	let date = new Date(parseInt(time) * 1000);
	let y = date.getFullYear();
	let MM = date.getMonth() + 1;
	MM = MM < 10 ? ('0' + MM) : MM;
	let d = date.getDate();
	d = d < 10 ? ('0' + d) : d;
	let h = date.getHours();
	h = h < 10 ? ('0' + h) : h;
	let m = date.getMinutes();
	m = m < 10 ? ('0' + m) : m;
	let s = date.getSeconds();
	s = s < 10 ? ('0' + s) : s;
	return y + '-' + MM + '-' + d
	// return y + '-' + MM + '-' + d;
}
export default {
	formatDate,
	formatDistance,
	formatDates
}